﻿using Md.Api.Model.Manage.SysRole.Request;
using Md.Dapper.Repositories.Md;

namespace Md.Api.Service.Manage.SysRole;
/// <summary>
/// 通过角色编号删除系统角色服务
/// </summary>
public class DeleteSysRoleByRoleIdService : ApiBase<RequestDeleteSysRoleByRoleIdModel>
{
    /// <summary>
    /// 系统角色仓储
    /// </summary>
    public SysRoleRep sysRoleRep { get; set; }
    /// <summary>
    /// 执行
    /// </summary>
    protected override void ExecuteMethod()
    {
        var ids = Parameter.RoleIds.Split(",");

        if (ids.Length == 0)
        {
            throw new AggregateException("角色编号不能为空");
        }

        int res = 0;

        foreach (var id in ids)
        {
            var delRes = sysRoleRep.DeleteSysRoleByRoleId(Convert.ToInt64(id));

            res += delRes;
        }

        Result.Data = res;
    }
}

